package com.aioething.iot.utils;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {
    public static <T> List<List<T>> getSubList(List<T> list,int len) {

        List<List<T>> listGroup = new ArrayList<>();
        if (list.size() <= len) {
            listGroup.add(list);
        } else {
            int count = list.size() / len;
            int surplus = list.size() % len;
            for (int i = 0; i < count; i++) {
                listGroup.add(list.subList(i * len, (i + 1) * len));
            }
            if (surplus > 0) {
                listGroup.add(list.subList(count * len, count * len + surplus));
            }
        }
        return listGroup;
    }

    public static String toString(List list, String separator) {
        return list.toString().replaceAll("[\\[\\] ]", "").replaceAll(",", separator);
    }
}
